package com.canbot.u05.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.canbot.u05.R;
import com.canbot.u05.activity.presidemode.PresideTaskRunActivity;
import com.canbot.u05.adapter.CompereAdapter;
import com.canbot.u05.bean.PresenterTask;
import com.canbot.u05.utils.Logger;
import com.canbot.u05.utils.ToastTools;

import java.util.concurrent.CopyOnWriteArrayList;

public class CompereFragment extends Fragment {

        public CopyOnWriteArrayList<PresenterTask> mListData;

        private CompereAdapter compereAdapter;

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
                View view = inflater.inflate(R.layout.fragment_compere, container, false);
                GridView mGridView = (GridView) view.findViewById(R.id.gv_content);
                compereAdapter = new CompereAdapter(getActivity(), mListData);
                mGridView.setOnItemClickListener(onItemClickListener);
                mGridView.setAdapter(compereAdapter);
                compereAdapter.notifyDataSetChanged();

                Logger.e("test", "onCreateView");

                return view;
        }

        @Override
        public void onResume() {
                super.onResume();
        }

        AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        ToastTools.newInstance(getActivity()).showText("position:" + mListData.get(position));
                        Intent intent = new Intent(getActivity(), PresideTaskRunActivity.class);
                        intent.putExtra("taskName", mListData.get(position).getTaskName());
                        startActivity(intent);
                }
        };
}
